Skip to content

fix(diplomacy): unequal treaty leader gets its trade bonus - #254

Merged
XxFran10xX merged 3 commits into
mainfrom
fix/unequal-treaty-trade
Nov 23, 2026
Merged

XxFran10xX merged 3 commits into
mainfrom
fix/unequal-treaty-trade

Conversation

@XxFran10xX

@XxFran10xX XxFran10xX commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Status record

  • Reviewed: Fable 5.2 (medium) at c5fe44c. Round 1 found 1 major issue (a stale agreement half softened an embargo) and 1 minor, both fixed; round 2 APPROVE. 6a7d7ce only adds a null guard for a visiting faction without a diplomacy handler (minor, no saved data), so no re-review.
  • Second opinion: CodeRabbit, no actionable comments.
  • Dev-tested: PASS at 6a7d7ce. TheHolyOrder was set as unequal-treaty leader over House_Malestroit, and its guild Keepers of Yeva's trade power went from 2824.56 (old jar) to 2835.75. The +11.19 matches +20% of its 55.9 raw trade in Malestroit's provinces. No SimpleFactions errors in the log; the Dev faction data was restored afterwards.
  • Local tests: TradeRelationHalvesTest 6/6, ProvinceManagerHubTransportTest 19/19, RealmRelationsBoundaryCoverageTest 24/24. Full suite on CI (9339 tests, coverage) green at 6a7d7ce.

Why

The Diplomacy menu promises the stronger side of an Unequal Treaty +20% trade power and +7.5% production for its guilds in the weaker side's land. That bonus never applied.

A guild trading in another faction's province only got the province owner's record of their trade relation. The other side's "our guilds in their territory" bonus was added only when the owner's type was mutual. The leader's bonus sits on the mutual leader type, and the weaker side holds the non-mutual unequal_treaty_subject. So in the weaker side's land, the leader's guilds got nothing, while the weaker side's +5% / +2.5% in the leader's land worked. The repo default diplomacy.yml has the same setup as Main.

What changed

  • DiplomacyHandler.getTradeModifiersFor reads both halves when the two records are the two halves of one relation: the owner's trade-effects-them plus the visitor's own trade-effects-us towards the owner. That is what the menu shows.
  • Unpaired records keep exactly the old owner-only reading. An embargo set over the other side's old agreement leaves that side's half behind, and counting it would soften the embargo.
  • Province.getModifiersForGuild checks both factions' records and passes the faction in hand, so there is no extra lookup by id in the province loop.
  • Income previews follow automatically, because both lookups go through getTradeRelation, which the preview overlays.
Owner record / visitor record Before After
Trade agreement / trade agreement +15 / +5 +15 / +5
Unequal leader / unequal subject (weaker side visiting) +5 / +2.5 +5 / +2.5
Unequal subject / unequal leader (leader visiting) nothing +20 / +7.5
Embargo / anything -95 / -95 -95 / -95

No unequal treaties exist on Main today, so no live faction's income changes at release.

🤖 Generated with Claude Code

XxFran10xX and others added 2 commits November 23, 2026 20:08
A guild trading in another faction's province only got the owner's record
of their trade relation ("their guilds in our territory"), plus the other
side's "our guilds" bonus only when the owner's type was mutual. The
leader's half of an unequal treaty is held on the mutual side, so the
leader's +20% trade power / +7.5% production never applied in the weaker
side's land, while the menu promised it.

Visiting guilds now get the owner's trade-effects-them plus their own
faction's trade-effects-us towards the owner. Trade agreements and
embargoes give the same results as before; income previews follow
because both lookups go through getTradeRelation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion

An embargo set over the other side's agreement leaves that side's old
half in place; adding it softened the embargo. Unpaired records keep the
owner-only reading, so only a matching pair (mutual type and its link)
reads both halves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c94a7512-802c-475c-8219-21c3058020bf

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Trade modifiers now reflect both sides of a faction’s trade relation, including mutual agreements and unequal treaties.
    • Province modifiers now account for trade relations recorded by either the province owner or the visiting faction.

DiplomacyHandler now calculates trade modifiers using relation records from both factions. Province modifier lookup checks for a trade relation on either side and passes the visiting Guild to the modifier calculation. Tests cover treaty, agreement, embargo, and empty-result cases.

Changes: Trade modifier resolution

Layer / File(s) Summary
Resolve and apply trade modifiers
src/main/java/net/tfminecraft/simplefactions/diplomacy/DiplomacyHandler.java, src/main/java/net/tfminecraft/simplefactions/map/provinces/Province.java, src/test/java/net/tfminecraft/simplefactions/diplomacy/TradeRelationHalvesTest.java
DiplomacyHandler resolves effects from linked relation records and adds an overload that accepts a Faction. Province.getModifiersForGuild checks for a relation in either direction and passes the visiting Guild. Tests cover unequal treaties, mutual agreements, embargoes, and empty results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: ryanbarlow97, drefvelin

Merge Risk: Minimal · previous review c5fe4

This change gives the unequal-treaty leader its trade bonus in the weaker side's land and leaves agreements and embargoes unchanged. No concrete merge-blocking problem was found. Normal CI and dev checks should complete before merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 102f337d-2660-4c46-bf72-bcc99c1af4db
Commits

Reviewing files that changed from the base of the PR and between 5cba0e0 and c5fe44c.

Files selected for processing: 3

  • src/main/java/net/tfminecraft/simplefactions/diplomacy/DiplomacyHandler.java
  • src/main/java/net/tfminecraft/simplefactions/map/provinces/Province.java
  • src/test/java/net/tfminecraft/simplefactions/diplomacy/TradeRelationHalvesTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Nov 23, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX
XxFran10xX merged commit ea30918 into main Nov 23, 2026
3 checks passed
@XxFran10xX
XxFran10xX deleted the fix/unequal-treaty-trade branch November 23, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant